home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / xdme_1.84_src.lha / XDME / Src / Mod / SharedCode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-06  |  5.0 KB  |  221 lines

  1.  
  2. /******************************************************************************
  3.  
  4.     MODULE
  5.     SharedCode.c
  6.  
  7.     DESCRIPTION
  8.     XDME Module
  9.     That module keeps some functions, which are shaerd by
  10.     different other modules.
  11.  
  12.     NOTES
  13.  
  14.     BUGS
  15.     none known
  16.  
  17.     TODO
  18.     tell me
  19.  
  20.     EXAMPLES
  21.  
  22.     SEE ALSO
  23.  
  24.     INDEX
  25.  
  26.     HISTORY
  27.     24-09-94 b_noll created
  28.     01-10-94 b_noll introduced DEFMESSAGE
  29.  
  30. ******************************************************************************/
  31.  
  32.  
  33. /**************************************
  34.           Includes
  35. **************************************/
  36.  
  37. #define AVL_H 1
  38. #include "defs.h"
  39.  
  40. /**************************************
  41.         Global Variables
  42. **************************************/
  43.  
  44.  
  45. /**************************************
  46.       Internal Defines & Structures
  47. **************************************/
  48.  
  49.  
  50. /**************************************
  51.        Internal Variables
  52. **************************************/
  53.  
  54.  
  55. /**************************************
  56.        Internal Prototypes
  57. **************************************/
  58.  
  59.  
  60. /**************************************
  61.          Macros
  62. **************************************/
  63.  
  64.  
  65. /**************************************
  66.          Implementation
  67. **************************************/
  68.  
  69. Prototype int is_Aborted (void);
  70. int is_Aborted (void)
  71. {
  72.     return GETF_ABORTCOMMAND( Ep );
  73. } /* is_aborted */
  74.  
  75. Prototype void set_Abortion (int val);
  76. void set_Abortion (int val)
  77. {
  78.     SETF_ABORTCOMMAND( Ep, val );
  79. } /* set_abortion */
  80.  
  81. Prototype void no_Memory (void);
  82. void no_Memory (void)
  83. {
  84.     nomemory();
  85. } /* no_Memory */
  86.  
  87.  
  88. Prototype APTR active_window (void);
  89. APTR active_window (void)
  90. {
  91.     return Ep->win;
  92. } /* active_window */
  93.  
  94.  
  95. int strpos (const char * str, int chr) {
  96.     char *in;
  97.     if ((in = strchr(str, chr)))
  98.     return (int)(in - str);
  99.     return -1;
  100. }
  101.  
  102. Prototype void strtrans (char * str, const char *find, const char *rep);
  103. void strtrans (char * str, const char *find, const char *rep)
  104. {
  105.     while (str = strpbrk(str, find)) {
  106.     *str = rep[strpos(find, *str)];
  107.     ++str;
  108.     } /* while */
  109. } /* strtrans */
  110.  
  111.  
  112.  
  113.  
  114. //Prototype int writefile (const char *, int (*writefunc)(FILE *, APTR), APTR);
  115. static int writefile (const char *filename, int (*writefunc)(FILE *, APTR), APTR data)
  116. {
  117.     FILE * fo;
  118.  
  119.     if ((fo = fopen(filename, "w"))) {
  120.     int rv;
  121.     rv = (*writefunc)(fo, data);
  122.     fclose(fo);
  123.     return rv;
  124.     } else {
  125. DEFMESSAGE( _SHARED_cant_open_outfile, "%s:\nCan't open file %s for output" )
  126.     error (_SHARED_cant_open_outfile, av[0], filename);
  127.     return RET_FAIL;
  128.     } /* if */
  129. } /* writefile */
  130.  
  131. Prototype int std_writefile (int (*writefunc)(FILE *, APTR), APTR);
  132. int std_writefile (int (*writefunc)(FILE *, APTR), APTR data)
  133. {
  134.     return writefile (av[1], writefunc, data);
  135. } /* std_writefile */
  136.  
  137.  
  138. //Prototype int readfile (const char *, int (*readfunc)(FILE *, APTR), APTR);
  139. static int readfile (const char *filename, int (*readfunc)(FILE *, APTR), APTR data)
  140. {
  141.     FILE * fi;
  142.  
  143.     if ((fi = fopen(filename, "r"))) {
  144.     int rv;
  145.     rv = (*readfunc)(fi, data);
  146.     fclose(fi);
  147.     return rv;
  148.     } else {
  149. DEFMESSAGE( _SHARED_cant_open_infile, "%s:\nCan't open file %s for input" )
  150.     error (_SHARED_cant_open_infile, av[0], filename);
  151.     return RET_FAIL;
  152.     } /* if */
  153. } /* readfile */
  154.  
  155. Prototype int std_readfile (int (*readfunc)(FILE *, APTR), APTR);
  156. int std_readfile (int (*readfunc)(FILE *, APTR), APTR data)
  157. {
  158.     return readfile (av[1], readfunc, data);
  159. } /* std_readfile */
  160.  
  161. Prototype int buffered_do_command (const char *str);
  162. int buffered_do_command (const char *str) {
  163.     char* buffer = strdup(str);                /* allocate a buffer and copy the command into that buffer */
  164.     if (buffer) {
  165.     int retval;
  166.     retval = do_command(buffer);           /* execute the buffer */
  167.     free(buffer);                          /* and then free it again */
  168.     return retval;
  169.     } else
  170.     nomemory();
  171.     return RET_FAIL;
  172. } /* buffered_do_command */
  173.  
  174. DEFMESSAGE( __on, "ON" )
  175. DEFMESSAGE( __off, "OFF" )
  176.  
  177.  
  178. Prototype int NodeStringComparison (struct Node *n1, STRPTR str);
  179. int NodeStringComparison (struct Node *n1, STRPTR str)
  180. {
  181. //printf ("NS: n/%08lx/`%s' <> s/%08lx/`%s'\n", n1, n1->ln_Name, str, str);
  182.     return strcmp (n1->ln_Name, str);
  183. } /* NodeStringComparison */
  184.  
  185. Prototype int NodeNodeComparison (struct Node *n1, struct Node *n2);
  186. int NodeNodeComparison (struct Node *n1, struct Node *n2)
  187. {
  188. //printf ("NN: n/%08lx/`%s' <> n/%08lx/`%s'\n", n1, n1->ln_Name, n2, n2->ln_Name);
  189.     return strcmp (n1->ln_Name, n2->ln_Name);
  190. } /* NodeNodeComparison */
  191.  
  192.  
  193.  
  194. /******************************************************************************
  195. *****  END SharedCode.c
  196. ******************************************************************************/
  197.  
  198.  
  199. int iAVL_Append (APTR x, APTR y, APTR z);
  200. int iAVL_Remove (APTR x, APTR y, APTR z);
  201. int iAVL_Find (APTR x, APTR y, APTR z);
  202. int iAVL_Append (APTR x, APTR y, APTR z)
  203. {
  204.     int AVL_Append (APTR x, APTR z);
  205.     return AVL_Append (x,z);
  206. }
  207.  
  208. int iAVL_Find (APTR x, APTR y, APTR z)
  209. {
  210.     int AVL_Find (APTR x, APTR z);
  211.     return AVL_Find (x,z);
  212. }
  213.  
  214. int iAVL_Remove (APTR x, APTR y, APTR z)
  215. {
  216.     int AVL_Remove (APTR x, APTR z);
  217.     return AVL_Remove (x,z);
  218. }
  219.  
  220.  
  221.